'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2007
'
' NAME: 
'
' AUTHOR: rhearn , MSIT
' DATE  : 2/20/2008
'
' COMMENT: 
'
'==========================================================================

WScript.StdOut.WriteLine " "
WScript.StdOut.WriteLine "------------------------------------------------ " 
WScript.StdOut.WriteLine "Command line arguments passed to the script: " 
WScript.StdOut.WriteLine "------------------------------------------------ " 
Dim i

For i = 0 to WScript.Arguments.Count - 1
    WScript.StdOut.WriteLine "Command line argument [" & i & "]:" & vbTab & WScript.Arguments(i) 
Next

WScript.StdOut.WriteLine "------------------------------------------------ " 
Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject") 
Dim oLogfile 
    
if (wscript.arguments.count = 1) then
    Set oFSO = CreateObject("Scripting.FileSystemObject") 
    Import wscript.arguments(0)
    
    Set oLogfile = oFSO.OpenTextFile("testing.log", ForWriting, True)
    TestFunctions   
    oLogfile.Close

Else
    WScript.StdOut.WriteLine
    WScript.StdOut.WriteLine "                                                                          " 
    WScript.StdOut.WriteLine "##########################################################################" 
    WScript.StdOut.WriteLine "##########################################################################" 
    WScript.StdOut.WriteLine "                                                                          " 
    WScript.StdOut.WriteLine "                                                                          " 
    WScript.StdOut.WriteLine " OemDeployment_TestBench.vbs USAGE:                                       " 
    WScript.StdOut.WriteLine " ---------------------------------------------                            " 
    WScript.StdOut.WriteLine "    cscript OemDeployment_TestBench.vbs filename.vbs                      " 
    WScript.StdOut.WriteLine "                                                                          " 
    WScript.StdOut.WriteLine "       filename.vbs is the name of the client-side script file            "
    WScript.StdOut.WriteLine "       (usually OemDeployment.vbs)                                        " 
    WScript.StdOut.WriteLine "                                                                          " 
    WScript.StdOut.WriteLine "##########################################################################" 
    WScript.StdOut.WriteLine "##########################################################################" 

End If

WScript.Quit(0)



Sub TestFunctions
'#############################################################################################
'#############################################################################################

    Do While True
    
        WriteLog(" ")
        WriteLog(" ")
        WriteLog(" ")
        WriteLog(" Test harness for OSD Client VBScript")
        WriteLog(" =====================================")
        WriteLog(" 1 : Run a task sequence using exported task sequence XML")
        WriteLog(" 2 : Run a group of steps from a task sequence")
        WriteLog(" 3 : Run a single step from a task sequence")
        WriteLog(" 4 : Set a Task Sequence variable from an XML file")
        WriteLog(" 5 : Save a Task Sequence Variable to an XML File")
        WriteLog(" 6 : Find & Replace variables in a text file")
        WriteLog(" 7 : Copy the SCCM log file to the mapped drive")
        WriteLog(" 8 : Display the value of a specific task sequence variable")
        WriteLog(" 9 : Show all task sequence variables")
        WriteLog(" ")
        WriteLog(" 0 : Execute a specific function or subroutine (go to submenu)")
        WriteLog(" ")
        WriteLog(" X : Exit")
        WriteLog(" ")
        WScript.StdOut.Write(" Your selection: ")
        Dim UserInput : UserInput = WScript.StdIn.ReadLine
        
        Select Case (UserInput)
            Case "1":
                TestTaskSequence
                
            Case "2":
                TestGroup
            
            Case "3":
                TestStep
                
            Case "4":
                Dim sVarName
                
                WScript.StdOut.Write("Enter the name of the TS variable to set: ")
                sVarName = WScript.StdIn.ReadLine
                If (sVarName <> "") Then
                    
                    WScript.StdOut.Write("Enter the name of the file: ")
                    UserInput = WScript.StdIn.ReadLine
                    
                    If (UserInput <> "") Then
                        If (oFSO.FileExists(UserInput)) Then
                            Dim oMyXml : Set oMyXml = CreateObject("Microsoft.XMLDOM") 
                            oMyXml.async = False 
                            oMyXml.load(UserInput)
                            Dim oTSE : Set oTSE = CreateObject("Microsoft.SMS.TSEnvironment") 
                            oTSE(sVarName) = oMyXml.xml
                        Else
                            WriteLog(" ")
                            WriteLog("File not found. Exiting...")
                            
                        End If
                    Else
                        WriteLog(" ")
                        WriteLog("File not found. Exiting...")
                        
                    End If
                Else
                    WriteLog(" ")
                    WriteLog("Exiting...")
                    
                End If
                
            
            Case "5":
                Dim sFilename, sVar, sVarValue
                
                WScript.StdOut.Write("Enter the name of the TS variable to get: ")
                sVar = WScript.StdIn.ReadLine
                If (sVar <> "") Then
                    Set oTSE = CreateObject("Microsoft.SMS.TSEnvironment") 
                    sVarValue = oTSE(sVar)
                    
                    WScript.StdOut.Write("Enter the name of the file to save: ")
                    UserInput = WScript.StdIn.ReadLine
                    
                    If (UserInput <> "") Then
                         Dim file : Set file = oFSO.CreateTextFile(sName)
                         file.Write(sVarValue)
                    Else
                        WriteLog(" ")
                        WriteLog("File not found. Exiting...")
                        
                    End If
                Else
                    WriteLog(" ")
                    WriteLog("Exiting...")
                    
                End If
                
                
            Case "6":
                WScript.StdOut.Write("Enter the name of the file: ")
                UserInput = WScript.StdIn.ReadLine
                ProcessFileVariables UserInput
            
            Case "7":
                CopyTsLogFile False
                
            Case "8":
                WScript.StdOut.Write("Enter the variable name to get the value of: ")
                UserInput = WScript.StdIn.ReadLine
                WriteLog("Variable: " & UserInput)
                WriteLog("Value   : " & GetTaskSequenceVariable(UserInput))
                
            Case "9":
                ShowAllTaskSequenceVariables
                
            Case "0":
                Dim oXmlFuncList : Set oXmlFuncList = GetFunctionList(wscript.arguments(0))
                TestSpecificFunction(oXmlFuncList)

            Case else:
                Exit Do
                 
        End Select
    Loop
    
'#############################################################################################
'#############################################################################################
End Sub

Sub TestTaskSequence

    WScript.StdOut.WriteBlankLines(10)
    WriteLog("Enter the path to the task sequence XML file")
    WriteLog(" ")
    WScript.StdOut.Write("> ")
    Dim sTSPath : sTSPath = WScript.StdIn.ReadLine
    
    If (Not oFSO.FileExists(sTSPath)) Then
        WScript.StdOut.Write "Error: XML File not found!"
        WScript.Quit
    End If
    
    WriteLog(" ")
    WriteLog(" ")
    WriteLog("Enter the path to the toolkit package directory")
    WriteLog(" ")
    WScript.StdOut.Write("> ")
    Dim sPkgPath : sPkgPath = WScript.StdIn.ReadLine
    
    If (Not oFSO.FolderExists(sPkgPath)) Then
        WScript.StdOut.Write "Error: Package path not found!"
        WScript.Quit
    End If
    
    SetTaskSequenceVariableFromXmlFile "TaskSequence", sTSPath
    
    Dim TsXml : Set TsXml = LoadXmlFromTsEnvironment("TaskSequence")
    If (TsXml Is Nothing) Then
        WScript.StdOut.Write "Error: Could not load task sequence xml!"
        WScript.Quit
    End If
    
    WScript.StdOut.Write "Task Sequence file loaded: " & sTSPath

    SetTaskSequenceVariable "_SMSTSLogPath", "X:\windows\temp\smstslog"
    sSMSTSLogFile = "SMSTS.LOG"
    sSMSTSLogFolder = sSMSTSLog & "\"
    SetTaskSequenceVariable "_SMSTSMachineName", GetSystemVariable("COMPUTERNAME")
    SetTaskSequenceVariable "WorkingDirectory", "X:\Windows\temp\smstslog\tap000000"

    
    Dim oTsBootImage : Set oTsBootImage = GetXmlNodeFromDoc(TsXml, "//SmsTaskSequencePackage/BootImageID")
    Dim sTsBootImage : sTsBootImage = oTsBootImage.Text
    
    Dim oTsName : Set oTsName = GetXmlNodeFromDoc(TsXml, "//SmsTaskSequencePackage/Name")
    Dim sTsName : sTsName = oTsName.Text
    WScript.StdOut.Write "Task Sequence Name: " & sTsName

    Dim TsSequence : TsSequence = GetXmlNodeFromDoc(TsXml, "//SequenceData/sequence")
    Dim TsSequenceChild
    
    For Each TsSequenceChild In TsSequence.ChildNodes
        If (TsSequenceChild.Name = "group") Then
            ProcessTsGroup(TsSequenceChild)
    
        ElseIf (TsSequenceChild.Name = "step") Then
            ProcessTsStep(TsSequenceChild)
        
        ElseIf (TsSequenceChild.Name  = "referenceList") Then
            Dim oTsRefPackages : set oTsRefPackages = GetXmlNodeListFromNode(TsSequenceChild, "./referenceList/reference")
            If (Not oTsRefPackages Is Nothing) Then
                Dim oTsRefPackage 
                WScript.StdOut.Write " "
                WScript.StdOut.Write "Referenced packages:"
                For Each oTsRefPackage In oTsRefPackages.ChildNodes
                    WScript.StdOut.Write "Package ID: " & oTsRefPackage.Attributes.getNamedItem("package").Text
                Next
                WScript.StdOut.Write " "
            Else
                WScript.StdOut.Write " "
                WScript.StdOut.Write "No packages in the 'Referenced packages' list (is this an error?)"
                WScript.StdOut.Write " "
            End if
        End If
    
    
    Next
    
   
        'Find all task steps (for my oem tools)
        '<step 
        '   type="HP_ProLiantDeployment" 
        '   name="Task name"
        '   description=
        '   runIn=
        '   successCodeList="0">
        '<action>smsswd.exe /run:TAP00104 cscript oddk.vbs auto HPDP</action>
        '<defaultVarList>
        '   <variable
        '       name="HPDPClientActions"
        '       property="ClientActions"> ... </variable>
        '   <variable
        '       name="HPDPControlValues"
        '       property="ControlValues">  ... </variable>
        '</defaultVarList>
        '</step>
        
        
        'execute
    
    'End If

End Sub

Sub TestGroup
End Sub

Sub TestStep
End Sub

Sub ProcessTsGroup(oTsGroup)
    'group header
    
    Dim sTsGroupName : sTsGroupName = oTsGroup.Attributes.getNamedItem("name")
    Dim sTsGroupDesc : sTsGroupDesc = oTsGroup.Attributes.getNamedItem("description")
    
    WriteLog(" ")
    WriteLog("Group Name   : " & sTsGroupName)
    WriteLog("  Description: " & sTsGroupDesc)

    If (oTsGroup.HasChildNodes) Then
        WriteLog(" (has " & oTsGroup.ChildNodes.Length & " child nodes) ")
        WriteLog(" ")

        Dim oTsGroupChild
        For Each oTsGroupChild In oTsGroup.ChildNodes
        
            If (oTsGroupChild.Name = "condition") Then
                ProcessTsCondition(oTsGroupChild)
            
            ElseIf (oTsGroupChild.Name = "step") Then
                ProcessTsStep(oTsGroupChild)
                
            ElseIf (oTsGroupChild.Name = "group") Then
                ProcessTsGroup(oTsGroupChild)
            End if
        
        Next
    Else
        WriteLog(" (no child nodes in this group) ")
    
    End If
    WriteLog(" ")

End Sub

Sub ProcessTsStep(oTsStep)
    
        Dim oAction : Set oAction = GetXmlNodeFromNode(oTsStep, "./action")
        If (oAction Is Nothing) Then
            SetError 1,3, "Action element not found within Step!"
        End If
        
        Dim actionName : actionName = oAction.Text
        Dim stepType : stepType = TsStep.Attributes.getNamedItem("type").Text
        Dim stepName : stepName = TsStep.Attributes.getNamedItem("name").Text
            
        If (InStr(actionName, "oddk.vbs") > 0) Then
            'found one of our tasks
            WriteLog(" ")
            WriteLog("Found one of our actions:")
            WriteLog("Name: " & stepName)
            WriteLog("Type: " & stepType)
            WriteLog(" ")
            WriteLog("Command line: " & actionName)
            WriteLog(" ")
            WriteLog("Variables:")
            WriteLog(" ")
            Dim variableList : Set variableList = GetXmlNodeListFromNode(oTsStep, "./defaultVarList/variable")
            If (variableList Is Nothing) Then
                SetError 1,3, "Variable elements not found within Step!"
            End If
            Dim oVariable
            for each oVariable In variableList
                Dim varName : varName = oVariable.Attributes.getNamedItem("name").Text
                Dim varProperty : varProperty = oVariable.Attributes.getNamedItem("property").Text
                Dim varhidden : varhidden = oVariable.Attributes.getNamedItem("hidden").Text
                Dim varValue : varValue = oVariable.text    
                WriteLog("Var name    : " & varName)
                WriteLog("Var property: " & varProperty)
                WriteLog("Var hidden? : " & varhidden)
                WriteLog("Value       : " & varValue)
                SetTaskSequenceVariable varName, varValue
            Next
            
            Dim oExec : Set oExec = gWshShell.Exec(actionName)
            Do While (oExec.Status = 0) 
                WScript.Sleep(100)
            Loop

            
        Else
            WriteLog(" ")
            WriteLog("Found another action (not our custom action):")
            WriteLog("Name: " & stepName)
            WriteLog("Type: " & stepType)
            WriteLog(" ")
            WriteLog("Command line: " & actionName)
            WriteLog(" ")
        End if

End Sub

Sub ProcessTsCondition(oTsCondition)


End Sub

Function GetFunctionList(sFileName)

    Dim objFs, WshShell, file, objFile, strLine
     
    Set objFs = CreateObject("Scripting.FileSystemObject")
    Set WshShell = CreateObject("WScript.Shell")
    sFileName = WshShell.ExpandEnvironmentStrings(sFileName)
    file = objFs.GetAbsolutePathName(sFileName)
    Set objFile = objFs.OpenTextFile(sFileName)
   
    'create XMLdoc
    Set objXMLDoc = CreateObject("Microsoft.XMLDOM") 
    objXMLDoc.async = False 
    
    objXMLDoc.loadXml("<Script></Script>") 
    
    Dim oFuncNode, objNewNode, objNewText, objParam, objParamText
    Dim varString, varStringArray
    Set oFuncNode = objXMLDoc.documentElement.selectSingleNode("//Script") 
    
    
    Do While (Not objFile.AtEndOfStream)
        strLine = objFile.ReadLine
        
        If (InStr(strLine, "Sub ") = 1) Or (InStr(strLine, "Function ") = 1) Then
            Dim strName : strName = strLine
            Set objNewNode = objXMLDoc.createElement("Proc") 
            
            If (InStr(strName, "(") > 0) Then
                strName = Left(strName, InStr(strName, "(") - 1)
            End If
            
            If (InStr(strName, "Sub ") = 1) Then
                strName = Replace(strName, "Sub ", "Sub      ")
            End If
            
            'Set objNewText = objXMLDoc.createTextNode(strName) 
            objNewNode.setAttribute "Name", strName
            'objNewNode.AppendChild(objNewText)
            
           
            If (InStr(strLine, "(") > 0) Then
                varString = Mid(strLine, InStr(strLine, "(") + 1 , InStr(strLine, ")") - InStr(strLine, "(") -1 )
                 'WriteLog("VarString: " & varString)
                 varStringArray = Split(varString, ",")
                 Dim var
                    For Each var In varStringArray
                        Set objParam = objXMLDoc.CreateElement("Parameter")
                        Set objParamText = objXMLDoc.createTextNode(Trim(var))
                        'objParam.nodeValue = Trim(var)
                        objParam.AppendChild(objParamText)
                        objNewNode.AppendChild(objParam)
                    Next
                
            End If
            oFuncNode.AppendChild(objNewNode)
            'WriteLog(" ")
            'WriteLog("New Node XML: " & objNewNode.Xml)
            
        End If
    Loop
   
    objFile.Close
    Set GetFunctionList = objXMLDoc   

End Function

Sub TestSpecificFunction(objXMLDoc)
    Dim UserInput
    
    WriteLog(" ")
    WriteLog("Testing specific function / subroutine code")
    WriteLog("===========================================")
    
    Dim oNodeParent, oProcNodes, i, n, oProcNode
    Set oProcNodes = objXMLDoc.SelectSingleNode("//Script").ChildNodes
        
    'Set oProcNodes = oNodeParent.ChildNodes
    i = 0
    'WriteLog("Found " & oProcNodes.Length & " procNodes")
            
    For n = 0 to oProcNodes.Length - 1
        WriteLog(" " & i & vbTab & oProcNodes.item(n).Attributes.getNamedItem("Name").Text)
        If (i > 0) And (i Mod 20 = 0) Then
            WriteLog(" ")
            WScript.StdOut.Write("Enter a number to run or Press ENTER to continue > ")
            UserInput = WScript.StdIn.ReadLine
            If (UserInput <> "") Then
                'WriteLog("You selected #" & UserInput)
                Exit For
            End If
            WriteLog(" ")
        End If
        i = i + 1
    Next
    If (UserInput = "") Then
        WriteLog(" ")
        WScript.StdOut.Write("Enter a number to run or Press ENTER to exit > ")
        UserInput = WScript.StdIn.ReadLine
        'WriteLog("You selected #" & UserInput)
    End If
    
    Dim x
    If (UserInput = "")  Then
        Exit Sub    
    ElseIf (IsNumeric(UserInput) = false) Then
        Exit Sub
    Else
        x = CInt(UserInput)
    End If
    
    If (x > oProcNodes.Length) Then
        Exit Sub
    End If
    Dim sProcName, retVal, sProctype, oSelectedProc, sVarType
    Dim sMyString, oMyXml, iMyNum, oMyFile, bMyBool
    ExecuteGlobal("Dim oXml1, oXml2, oXml3, sMyString1, sMyString2, sMyString3, iMyNum1, iMyNum2, iMyNum3")
    ExecuteGlobal("Dim bMyBool1, bMyBool2, bMyBool3, oFile1, oFile2, oFile3, sFileName1, sFileName2, sFileName3")
    Dim stringCount : stringCount = 1
    Dim xmlCount : xmlCount = 1
    Dim numCount : numCount = 1
    Dim boolCount : boolCount = 1
    Dim fileCount : fileCount = 1
    Dim fileNameCount : fileNameCount = 1
    
    Dim arrParameters
    
    sProcName = oProcNodes.item(x).Attributes.getNamedItem("Name").Text
    If (InStr(sProcName, "(") > 0) Then
        sProcName = Left(sProcName, InStr(sProcName, "(") - 1)
    End If
        
    If (InStr(sProcName, "Sub ") = 1) Then
        sProctype = "Sub"
        sProcName = Right(sProcName, Len(sProcName) - 4)
    ElseIf (InStr(sProcName, "Function ") = 1) Then
        sProctype = "Function"
        sProcName = Right(sProcName, Len(sProcName) - 9)
    End If

    WriteLog(" ")
    WriteLog("Procedure type  : " & Trim(sProctype))
    WriteLog("Procedure name  : " & Trim(sProcName))
    
    If (oProcNodes.item(x).HasChildNodes) Then
        WriteLog("Parameters      : " & oProcNodes.item(x).ChildNodes.Length)
        Dim variable, variables, j
        'ReDim arrParameters (oProcNodes.item(x).ChildNodes.Length)
        WriteLog(" ")
        'WriteLog(" UBound(arrParameters) = " & UBound(arrParameters))
        WriteLog(" ")
        WriteLog(" ")
        For j = 0 To  oProcNodes.item(x).ChildNodes.Length - 1
            If (j > 0) Then
                arrParameters = arrParameters & ", "
            End if
            WriteLog("=======================================")
            WriteLog(" Parameter " & j + 1& ": '" & oProcNodes.item(x).ChildNodes.item(j).text & "'")
            WriteLog(" ")
            WriteLog(" What is this parameter's type?")
            WriteLog(" ")
            WriteLog("    1 : string")
            WriteLog("    2 : file name")
            WriteLog("    3 : file object (input)")
            WriteLog("    4 : file object (output)")
            WriteLog("    5 : file contents (string)")
            WriteLog("    6 : number")
            WriteLog("    7 : xml document object")
            WriteLog("    8 : xml node list object")
            WriteLog("    9 : xml node object")
            WriteLog("    0 : boolean")
            
            WriteLog(" ")
            WScript.StdOut.Write(" Enter a number: ")
            sVarType = WScript.StdIn.ReadLine
            
            Select Case (sVarType)
                Case "1":
                    WriteLog(" ")
                    WScript.StdOut.Write("Enter the string to use for this parameter: ")
                    sMyString = WScript.StdIn.ReadLine
                    If (sMyString <> "") Then
                        sMyString = sMyString
                        If (stringCount = 1) Then
                            sMyString1 = sMyString
                            arrParameters = arrParameters & "sMyString1"
                        ElseIf (stringCount = 2) Then
                            sMyString2 = sMyString
                            arrParameters = arrParameters & "sMyString2"
                        ElseIf (stringCount = 3) Then
                            sMyString3 = sMyString
                            arrParameters = arrParameters & "sMyString3"
                        End If
                        stringCount = stringCount + 1
                        WriteLog("stringCount = " & stringCount)
                        
                    Else
                        WriteLog(" ")
                        WriteLog("Exiting...")
                        Exit Sub
                    End If
                    WriteLog("arrParameters: " & arrParameters)
        
                Case "2":
                    WriteLog(" ")
                    WScript.StdOut.Write("Enter the file name (with path if necessary)" & VbCrLf & "to use for this parameter: ")
                    sMyString = WScript.StdIn.ReadLine
                    If (sMyString <> "") Then
                        If (fileNameCount = 1) Then
                            sFileName1 = sMyString
                            arrParameters = arrParameters & "sFileName1"
                        ElseIf (fileNameCount = 2) Then
                            sFileName2 = sMyString
                            arrParameters = arrParameters & "sFileName2"
                        ElseIf (fileNameCount = 3) Then
                            sFileName3 = sMyString
                            arrParameters = arrParameters & "sFileName3"
                        End If
                        fileNameCount = fileNameCount + 1
                        WriteLog("fileNameCount = " & fileNameCount)
                        
                    Else
                        WriteLog(" ")
                        WriteLog("Exiting...")
                        Exit Sub
                    End If
                    WriteLog("arrParameters: " & arrParameters)
                
                Case "3":
                    WriteLog(" ")
                    WriteLog("Enter the file name (with path if necessary)" & VbCrLf & "to use for this parameter.")
                    WScript.StdOut.Write("It will be opened for reading. >")
                    sMyString = WScript.StdIn.ReadLine
                    If (sMyString <> "") then
                        Set objFs = CreateObject("Scripting.FileSystemObject")
                        sMyString = objFs.GetAbsolutePathName(sMyString)
                        Set oMyFile1 = objFs.OpenTextFile(sMyString, ForReading, true)
                        If (fileCount = 1) Then
                            Set oFile1 = oMyFile1
                            arrParameters = arrParameters & "oFile1"
                        ElseIf (fileCount = 2) Then
                            Set oFile2 = oMyFile1
                            arrParameters = arrParameters & "oFile2"
                        ElseIf (fileCount = 3) Then
                            Set oFile3 = oMyFile1
                            arrParameters = arrParameters & "oFile3"
                        End If
                        fileCount = fileCount + 1
                        WriteLog("fileCount = " & fileCount)
                        
                    Else
                        WriteLog(" ")
                        WriteLog("Exiting...")
                        Exit Sub
                    End If
                    WriteLog("arrParameters: " & arrParameters)
                    
                 Case "4":
                    WriteLog(" ")
                    WriteLog("Enter the file name (with path if necessary)" & VbCrLf & "to use for this parameter.")
                    WScript.StdOut.Write("It will be opened for writing. > ")
                    sMyString = WScript.StdIn.ReadLine
                    If (sMyString <> "") Then
                        Set objFs = CreateObject("Scripting.FileSystemObject")
                        sMyString = objFs.GetAbsolutePathName(sMyString)
                        Set oMyFile = objFs.OpenTextFile(sMyString, ForWriting, true)
                        
                        If (fileCount = 1) Then
                            Set oFile1 = oMyFile
                            arrParameters = arrParameters & "oFile1"
                        ElseIf (fileCount = 2) Then
                            Set oFile2 = oMyFile
                            arrParameters = arrParameters & "oFile2"
                        ElseIf (fileCount = 3) Then
                            Set oFile3 = oMyFile
                            arrParameters = arrParameters & "oFile3"
                        End If
                        fileCount = fileCount + 1
                        WriteLog("fileCount = " & fileCount)
                        
                    Else
                        WriteLog(" ")
                        WriteLog("Exiting...")
                        Exit Sub
                    End If
                    WriteLog("arrParameters: " & arrParameters)
                    
                    
                Case "5":
                    WriteLog(" ")
                    WriteLog("Enter the file name (with path if necessary)" & VbCrLf & "to use for this parameter.")
                    WScript.StdOut.Write("It will be opened and read into a string > ")
                    sMyString = WScript.StdIn.ReadLine
                    If (sMyString <> "") Then
                        Set objFs = CreateObject("Scripting.FileSystemObject")
                        WriteLog(" ")
                        WriteLog(" > Created a '" & TypeName(objFs) & "' object.")
                        sMyString = objFs.GetAbsolutePathName(sMyString)
                        Set oMyFile1 = objFs.OpenTextFile(sMyString)
                        WriteLog(" ")
                        WriteLog(" > Created a '" & TypeName(oMyFile1) & "' object.")
                        sMyString = oMyFile1.ReadAll
                        
                        If (fileNameCount = 1) Then
                            sFileName1 = sMyString
                            arrParameters = arrParameters & "sFileName1"
                        ElseIf (fileNameCount = 2) Then
                            sFileName2 = sMyString
                            arrParameters = arrParameters & "sFileName2"
                        ElseIf (fileNameCount = 3) Then
                            sFileName3 = sMyString
                            arrParameters = arrParameters & "sFileName3"
                        End If
                        fileNameCount = fileNameCount + 1
                        WriteLog("fileNameCount = " & fileNameCount)
                        
                        objFile.Close
                        
                    Else
                        WriteLog(" ")
                        WriteLog("Exiting...")
                        Exit Sub
                    End If
                    WriteLog("arrParameters: " & arrParameters)
                    
                Case "6":
                    WriteLog(" ")
                    WScript.StdOut.Write("Enter the number to use for this parameter: ")
                    iMyNum = WScript.StdIn.ReadLine
                    If (iMyNum <> "") Then
                        If (numCount = 1) Then
                            iMyNum1 = CInt(iMyNum)
                            arrParameters = arrParameters & "sFileName1"
                        ElseIf (numCount = 2) Then
                            iMyNum1 = CInt(iMyNum)
                            arrParameters = arrParameters & "sFileName2"
                        ElseIf (numCount = 3) Then
                            iMyNum1 = CInt(iMyNum)
                            arrParameters = arrParameters & "sFileName3"
                        End If
                        numCount = numCount + 1
                        WriteLog("numCount = " & numCount)
                        
                    Else
                        WriteLog(" ")
                        WriteLog("Exiting...")
                        Exit Sub
                    End If
                    WriteLog("arrParameters: " & arrParameters)
                
                Case "7":
                    WriteLog(" ")
                    WriteLog("Enter the file name (with path if necessary) to the XML file.")
                    WScript.StdOut.Write("It will be opened into an Xml Document object: ")
                    sMyString = WScript.StdIn.ReadLine
                    If (sMyString <> "") then
                        Set oMyXml = CreateObject("Microsoft.XMLDOM") 
                        WriteLog(" ")
                        WriteLog(" > Created a '" & TypeName(oMyXml) & "' object.")
                        oMyXml.async = False 
                        oMyXml.load(sMyString)
                        
                        If (xmlCount = 1) Then
                            Set oXml1 = oMyXml
                            arrParameters = arrParameters & "oXml1"
                        ElseIf (xmlCount = 2) Then
                            Set oXml2 = oMyXml
                            arrParameters = arrParameters & "oXml2"
                        ElseIf (xmlCount = 3) Then
                            Set oXml3 = oMyXml
                            arrParameters = arrParameters & "oXml3"
                        End If
                        xmlCount = xmlCount + 1
                        WriteLog("xmlCount = " & xmlCount)
                        
                    Else
                        WriteLog(" ")
                        WriteLog("Exiting...")
                        Exit Sub
                    End if  
                    WriteLog(arrParameters)                                  
                    
                Case "8":
                    WriteLog(" ")
                    WScript.StdOut.Write("Enter the file name (with path if necessary) to the XML file: ")
                    sMyString = WScript.StdIn.ReadLine
                    If (sMyString <> "") then
                    
                        Set oMyXml = CreateObject("Microsoft.XMLDOM") 
                        WriteLog(" ")
                        WriteLog(" > Created a '" & TypeName(oMyXml) & "' object.")
                        oMyXml.async = False
                        oMyXml.load(sMyString)
                        
                        WriteLog(" ")
                        WScript.StdOut.Write("Enter the XPath query to define the node list (no quotes): ")
                        sMyString = WScript.StdIn.ReadLine
                        
                        If (sMyString <> "") Then
                            Set oMyXml = oMyXml.documentElement.selectNodes(sMyString) 
                            WriteLog(" ")
                            WriteLog(" > Created a '" & TypeName(oMyXml) & "' object.")
                        
                            If (xmlCount = 1) Then
                                Set oXml1 = oMyXml
                                arrParameters = arrParameters & "oXml1"
                            ElseIf (xmlCount = 2) Then
                                Set oXml2 = oMyXml
                                arrParameters = arrParameters & "oXml2"
                            ElseIf (xmlCount = 3) Then
                                Set oXml3 = oMyXml
                                arrParameters = arrParameters & "oXml3"
                            End If
                            xmlCount = xmlCount + 1
                            WriteLog("xmlCount = " & xmlCount)
                            
                        Else
                            WriteLog(" ")
                            WriteLog("Exiting...")
                            Exit Sub
                        End If
                    Else
                        WriteLog(" ")
                        WriteLog("Exiting...")
                        Exit Sub
                    End If
                    WriteLog("arrParameters: " & arrParameters)
                
                Case "9":
                    WriteLog(" ")
                    WScript.StdOut.Write("Enter the file name (with path if necessary) to the XML file: ")
                    sMyString = WScript.StdIn.ReadLine
                    If (sMyString <> "") then
                        Set oMyXml = CreateObject("Microsoft.XMLDOM") 
                        WriteLog(" ")
                        WriteLog(" > Created a '" & TypeName(oMyXml) & "' object.")
                        oMyXml.async = False
                        oMyXml.load(sMyString)
                        
                        WriteLog(" ")
                        WScript.StdOut.Write("Enter the XPath query to define the node (no quotes): ")
                        sMyString = WScript.StdIn.ReadLine
                        If (sMyString <> "") then
                            Dim oMyXmlNode : Set oMyXmlNode = oMyXml.documentElement.selectSingleNode(sMyString)  
                            WriteLog(" ")
                            WriteLog(" > Created a '" & TypeName(oMyXmlNode) & "' object.")
                            
                            If (xmlCount = 1) Then
                                Set oXml1 = oMyXmlNode
                                arrParameters = arrParameters & "oXml1"
                            ElseIf (xmlCount = 2) Then
                                Set oXml2 = oMyXmlNode
                                arrParameters = arrParameters & "oXml2"
                            ElseIf (xmlCount = 3) Then
                                Set oXml3 = oMyXmlNode
                                arrParameters = arrParameters & "oXml3"
                            End If
                            xmlCount = xmlCount + 1
                            WriteLog("xmlCount = " & xmlCount)
                                              
                        Else
                            WriteLog(" ")
                            WriteLog("Exiting...")
                            Exit Sub
                        End If
                    Else
                        WriteLog(" ")
                        WriteLog("Exiting...")
                        Exit Sub
                    End If
                    WriteLog("arrParameters: " & arrParameters)
                    
                    
                Case "0":
                    
                    WriteLog(" ")
                    WScript.StdOut.Write("Enter the boolean value to use for this parameter: ")
                    sMyString = WScript.StdIn.ReadLine
                    If (sMyString <> "") Then
                        bMyBool = CBool(sMyString)
                        If (boolCount = 1) Then
                            bMyBool1 = bMyBool
                            arrParameters = arrParameters & "bMyBool1"
                        ElseIf (boolCount = 2) Then
                            bMyBool2 = bMyBool
                            arrParameters = arrParameters & "bMyBool2"
                        ElseIf (boolCount = 3) Then
                            bMyBool3 = bMyBool
                            arrParameters = arrParameters & "bMyBool3"
                        End If
                        boolCount = boolCount + 1
                        WriteLog("boolCount = " & boolCount)
                    Else
                        WriteLog(" ")
                        WriteLog("Exiting...")
                        Exit Sub
                    End If
                    WriteLog("arrParameters: " & arrParameters)
                    
                Case else:
                    WriteLog(" ")
                    WriteLog("Exiting...")
                    Exit Sub
            End Select
            
           ' WriteLog("arrParameters: " & arrParameters)
            
        Next
    
    End If

    Dim cmdLine
    ExecuteGlobal("Dim returnValue")
                    
    
    If (sProctype = "Sub") Then
        cmdLine = Trim(sProcName)
        WriteLog("cmdline: " & cmdline)
        If (oProcNodes.item(x).HasChildNodes) then
            If (Len(arrParameters) > 0) Then
                cmdLine = cmdLine & " " & arrParameters
            End If
        End If
        WriteLog("Command line to execute: " & cmdLine)
        ExecuteGlobal(cmdLine)
        
    Else
        WriteLog(" ")
        WScript.StdOut.Write("Is the return value an OBJECT? (Y/N): ")
        Dim sIsAnObject : sIsAnObject = WScript.StdIn.ReadLine
        
        If (sIsAnObject = "Y") or (sIsAnObject = "y") then
            cmdLine = "set returnValue = " & sProcName
        Else
            cmdLine = "returnValue = " & sProcName
        End If
        If (oProcNodes.item(x).HasChildNodes) then
            If (Len(arrParameters) > 0) Then
                cmdLine = cmdLine & "(" & arrParameters & ")"
            End If
        End If
        WriteLog(" ")
        WriteLog("Command line to execute: " & cmdLine)
        ExecuteGlobal(cmdLine)

        Dim checkValue : checkValue = VarType(returnValue)
        WriteLog(" ")
        'WriteLog("Checkvalue = " & checkValue)
        WriteLog(" ")
        Dim objectType
        Select Case (checkValue)
        
            Case vbEmpty:
                 SetError 1,3, "Value returned from the function was empty / uninitialized"
    
            Case vbNull:
                SetError 1,3, "Value returned from the function was null"
                
            Case vbError:
                WriteLog(" ")
                WriteLog("Value returned from the function was an error: " & CStr(returnValue))
    
            Case vbInteger:
                WriteLog(" ")
                WriteLog("Integer value returned: " & CStr(returnValue))    
                
    
            Case vbString:
                WriteLog(" ")
                WriteLog("String value returned: '" & returnValue & "'")    
    
            Case vbDate:
                WriteLog(" ")
                WriteLog("Date value returned: " & CStr(returnValue))    
    
            Case vbSingle:
                WriteLog(" ")
                WriteLog("Single value returned: " & CStr(returnValue))   
    
            Case vbDouble:
                WriteLog(" ")
                WriteLog("Double value returned: " & CStr(returnValue))    
    
            Case vbLong:
                WriteLog(" ")
                WriteLog("Long value returned: " & CStr(returnValue))   
    
            Case vbByte:
                WriteLog(" ")
                WriteLog("Byte value returned: " & CStr(returnValue))     
    
            Case vbCurrency:
                WriteLog(" ")
                WriteLog("Currency value returned: " & CStr(returnValue))    
    
            Case vbVariant:
                WriteLog(" ")
                WriteLog("A variant type was returned from the function (used only with arrays of Variants).")    
                
            Case vbDataObject:
                WriteLog(" ")
                WriteLog("A data object was returned from the function.")    
                
            Case vbObject:
                WriteLog(" ")
                WriteLog("An object was returned from the function. Now determining object type.") 
                objectType = TypeName(returnValue)
                WriteLog(" ")
                WriteLog("The object type is:  '" & objectType & "'") 
               
                If (objectType = "DOMDocument") Then            'an xml document
                    WriteLog(" ")
                    WriteLog("Contents of the XML: " & VbCrLf & returnValue.Xml) 
                
                ElseIf (objectType = "IXMLDOMSelection") Then   'an xml nodelist
                    WriteLog(" ")
                    WriteLog("Contents of the XML: " & VbCrLf & returnValue.Xml) 
                
                ElseIf (objectType = "IXMLDOMElement") Then    ' an xml node
                    WriteLog(" ")
                    WriteLog("Contents of the XML: " & VbCrLf & returnValue.Xml) 
                
                
                ElseIf (objectType = "IMatchCollection2") Then     'matches from a regex search
                    WriteLog(" ")
                    WriteLog("Contents of the matches: ") 
                    Dim oMatch 
                    For Each oMatch In returnValue
                        WriteLog("  " & oMatch.Value)
                    Next                    
                End If
            
            Case vbBoolean:
                WriteLog(" ")
                WriteLog("Boolean value returned: " & CStr(returnValue))    
            
            Case vbArray:
                WriteLog(" ")
                WriteLog("An array was returned from the function. array values below")    
                Dim y
                for y = 0 to Ubound(returnValue)
                    WriteLog(" " & x & " : " & returnValue(y))
                 Next
                
        End Select
    End If
        
   
    WriteLog(" ")
    WScript.StdOut.Write("Press <ENTER> to continue > ")
    sMyString = WScript.StdIn.ReadLine
    Set returnvalue = Nothing
    
        
End Sub

Sub WriteLog(sText)

    Wscript.StdOut.WriteLine(sText)
    oLogfile.WriteLine(sText)

End Sub

Function GetSampleXmlTaskNode()
    'point to task sequence XML (can be valid or invalid)
    'let user choose task node to retrieve
    
    'alternatively user can input null or any string or object

End Function



Sub Import(ByVal strFile)

   Set objFs = CreateObject("Scripting.FileSystemObject")
   Set WshShell = CreateObject("WScript.Shell")
   strFile = WshShell.ExpandEnvironmentStrings(strFile)
   file = objFs.GetAbsolutePathName(strFile)
   Set objFile = objFs.OpenTextFile(strFile)
   strCode = objFile.ReadAll
   objFile.Close
   ExecuteGlobal(strCode)

End Sub

